package action.plan;

import java.util.List;

import org.springframework.security.context.SecurityContext;
import org.springframework.security.context.SecurityContextHolder;

import persistence.model.TdfkfaBasicInvest;
import persistence.model.TdfkfaBasicScxmgk;
import persistence.model.TdfkfaBasicXmqntdphlx;
import persistence.model.TdfkfaBasicXmqtdlyxz;
import persistence.model.TdfkfaBasicYqfkmj;
import persistence.model.TdfkfaComposeUnit;
import persistence.model.TdfkfaMain;
import persistence.model.TdfkfaPrjDxtp;
import persistence.model.TdfkfaUser;
import service.PlanService;
import service.UserService;

import com.opensymphony.xwork2.ActionSupport;

import constant.DictConstant;

public class ModifyPlanAction extends ActionSupport {

    private static final long serialVersionUID = -1866234016444492149L;

    private PlanService planService;

    private UserService userService;

    private Integer planId;

    private TdfkfaMain main;

    private TdfkfaBasicXmqntdphlx phlx;

    private TdfkfaBasicScxmgk xmgk;

    private TdfkfaBasicYqfkmj fkmj;

    private TdfkfaBasicXmqtdlyxz lyxz;

    private TdfkfaBasicInvest fktz;

    private TdfkfaComposeUnit unit;

    private List<TdfkfaPrjDxtp> dxtpList;

    private String returnCode;

    private String returnDetail;

    public String prepare() throws Exception {
        SecurityContext ctx = SecurityContextHolder.getContext();
        String username = ctx.getAuthentication().getName();
        TdfkfaUser user = userService.getUserByUsername(username);
        planId = user.getPlanId();
        main = planService.getPlanMain(planId);
        if (planId == null || !main.getPrjFaztcode().equals(new Short(DictConstant.FAZT_EDITING))) {
            returnCode = "failure";
            returnDetail = "没有方案可供修改";
        } else {
            phlx = planService.getPlanPhlx(planId);
            xmgk = planService.getPlanXmgk(planId);
            fkmj = planService.getPlanFkmj(planId);
            lyxz = planService.getPlanLyxz(planId);
            fktz = planService.getPlanFktz(planId);
            unit = planService.getPlanUnit(planId);
            dxtpList = planService.getPlanDxtp(planId);
            returnCode = "success";
        }
        return SUCCESS;
    }

    public void setPlanService(PlanService planService) {
        this.planService = planService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    public Integer getPlanId() {
        return planId;
    }

    public void setPlanId(Integer planId) {
        this.planId = planId;
    }

    public TdfkfaMain getMain() {
        return main;
    }

    public void setMain(TdfkfaMain main) {
        this.main = main;
    }

    public TdfkfaBasicXmqntdphlx getPhlx() {
        return phlx;
    }

    public void setPhlx(TdfkfaBasicXmqntdphlx phlx) {
        this.phlx = phlx;
    }

    public TdfkfaBasicScxmgk getXmgk() {
        return xmgk;
    }

    public void setXmgk(TdfkfaBasicScxmgk xmgk) {
        this.xmgk = xmgk;
    }

    public TdfkfaBasicYqfkmj getFkmj() {
        return fkmj;
    }

    public void setFkmj(TdfkfaBasicYqfkmj fkmj) {
        this.fkmj = fkmj;
    }

    public TdfkfaBasicXmqtdlyxz getLyxz() {
        return lyxz;
    }

    public void setLyxz(TdfkfaBasicXmqtdlyxz lyxz) {
        this.lyxz = lyxz;
    }

    public TdfkfaBasicInvest getFktz() {
        return fktz;
    }

    public void setFktz(TdfkfaBasicInvest fktz) {
        this.fktz = fktz;
    }

    public TdfkfaComposeUnit getUnit() {
        return unit;
    }

    public void setUnit(TdfkfaComposeUnit unit) {
        this.unit = unit;
    }

    public String getReturnCode() {
        return returnCode;
    }

    public void setReturnCode(String returnCode) {
        this.returnCode = returnCode;
    }

    public String getReturnDetail() {
        return returnDetail;
    }

    public void setReturnDetail(String returnDetail) {
        this.returnDetail = returnDetail;
    }

    public List<TdfkfaPrjDxtp> getDxtpList() {
        return dxtpList;
    }

    public void setDxtpList(List<TdfkfaPrjDxtp> dxtpList) {
        this.dxtpList = dxtpList;
    }

}
